package com.xmy.cultivate.config;

import com.xmy.cultivate.constant.MessageType;
import com.xmy.cultivate.context.ContextMessageFactory;
import com.xmy.cultivate.service.message.EventMessageService;
import com.xmy.cultivate.service.message.ImageMessageService;
import com.xmy.cultivate.service.message.NewsMessageService;
import com.xmy.cultivate.service.message.TextMessageService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageConfig {

    private ApplicationContext applicationContext;

    public MessageConfig(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Bean
    public ContextMessageFactory getContextMessageFactory() {
        ContextMessageFactory contextMessageFactory = new ContextMessageFactory();
        contextMessageFactory.builder(MessageType.IMAGE, applicationContext.getBean(ImageMessageService.class))
                .builder(MessageType.TEXT, applicationContext.getBean(TextMessageService.class))
                .builder(MessageType.LINK, applicationContext.getBean(NewsMessageService.class))
                .builder(MessageType.EVENT, applicationContext.getBean(EventMessageService.class));
        return contextMessageFactory;
    }

}